package com.ych.modules.cms.authorInfc.user.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ych.modules.base.dbEntity.TUserFeedbackEntity;
import com.ych.modules.common.entity.modify.ReplyFeedbackEntity;
import com.ych.modules.common.entity.query.QueryUserFeedbackEntity;
import com.ych.modules.common.service.UserFeedbackService;
import com.ych.utils.mysqlPageUtil.PageUtils;
import com.ych.utils.serviceReturn.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2020/12/31
 * Time: 15:43
 * Description:
 */
@RestController("cmsUserFeedbackController")
@RequestMapping("/cms/auth/user/feedback")
@Api(tags = {"CMS——用户反馈"}, description = "CMS——用户反馈", position = 2)
public class UserFeedbackController {
    @Autowired
    private UserFeedbackService userFeedbackService;

    @PostMapping("/listUserFeedback")
    @ApiOperation(value = "用户反馈列表查询", notes = "用户反馈列表查询")
    public R<Page<TUserFeedbackEntity>> listUserFeedback(@RequestBody QueryUserFeedbackEntity entity) {
        try {
            Page<TUserFeedbackEntity> page = userFeedbackService.listUserFeedback(entity);
            return new R(0, "成功", new PageUtils(page));
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/replyFeedback")
    @ApiOperation(value = "回复反馈", notes = "回复反馈")
    public R<String> replyFeedback(@RequestBody ReplyFeedbackEntity entity) {
        try {
            userFeedbackService.replyFeedback(entity);
            return new R(0, "成功", null);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/getFeedback")
    @ApiOperation(value = "查询反馈信息", notes = "查询反馈信息")
    public R<TUserFeedbackEntity> getFeedback(@RequestBody String feedbackId) {
        try {
            TUserFeedbackEntity entity = userFeedbackService.getFeedback(feedbackId);
            return new R(0, "成功", entity);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }
}
